(function(){
	var api = 'http://h6.duchengjiu.top/shop/';
	//热门商品
	var oCpzszd = document.getElementById('cpzszd');
	var cartId = getUrlValue('cat_id');
	//console.log(getUrlValue('cat_id'));
	//console.log(oMored);
	var  templateStr= document.getElementById('splbzdx').innerHTML;
	
	//console.log(oCpzszd);
	//console.log(templateStr);
	var pages = 1;//当前页
	var pageCount;//总页数
	//console.log(cartId);
			$.get(api + 'api_goods.php',{'cat_id':cartId,'page':1,"pagesize":9},function(data){
			console.log(data);
			if(data.code ==1 ){
				oCpzszd.innerHTML = '客官别急，新品马上上架';
				return;
			};
			pageCount = data.page.page_count;
			var obj=data.data;
			//console.log(data);
			var str = '';
			var tempile = _.template(templateStr);
			for(var i=0;i<obj.length;i++){
				str += tempile(obj[i])
			};
			oCpzszd.innerHTML += str;
			
			var aDl = document.getElementById('cpzszd').getElementsByTagName('dl');
			console.log(obj)
			for(var a=0;a<aDl.length;a++){
				//console.log(this);
				aDl[a].style.margin = '20px 23px 0 0';
//				if( (obj[a].id+1)%3 == 0){
//					aDl[a].style.margin = '20px 0 0 0';
//				};
			};
			$('[lazyloadsrc]').YdxLazyLoad();
			
			$('.pageNav').pagination({
				pageCount : pageCount, //总多少页
				//current : 1, //默认当前第几页
				activeCls : 'haha', //当前选中页样式
				prevContent: '上一页',
				nextContent: '下一页',
				mode : 'fixed',
				count: 4,
				coping: true,
				homePage : '首页',
				endPage : '尾页',
				jump : true,
				callback: function(apis){
					var activePage = apis.getCurrent();
					//console.log(activePage);
					$.get(api + 'api_goods.php',{'cat_id':cartId,'page':activePage,"pagesize":9},function(data){
					console.log(data);
					if(data.code ==1 ){
						oCpzszd.innerHTML = '客官别急，新品马上上架';
						return;
					};
					pageCount = data.page.page_count;
					var obj=data.data;
					//console.log(data);
					var str = '';
					var tempile = _.template(templateStr);
					for(var i=0;i<obj.length;i++){
						str += tempile(obj[i])
					};
					oCpzszd.innerHTML = str;
					
					var aDl = document.getElementById('cpzszd').getElementsByTagName('dl');
					console.log(obj)
					for(var a=0;a<aDl.length;a++){
						//console.log(this);
						aDl[a].style.margin = '20px 23px 0 0';
		//				if( (obj[a].id+1)%3 == 0){
		//					aDl[a].style.margin = '20px 0 0 0';
		//				};
					};
					$('[lazyloadsrc]').YdxLazyLoad();
					
					});
					
				},
			});
			});
		
})();

//console.log(window.location)
//这个方法用来干 什么的？
function getUrlValue(name){//?goods_id=257557&age=haha
		var str = location.search.substr(1);//goods_id=257557
		var reg = new RegExp("(^|&)"+name+"=([^&]*)(&|$)");
		var result = str.match(reg);
		//console.log(result)
		//console.log(result);
		if(result === null) return null;
		return result[2];
};